package com.example.controller;

import com.example.bean.UserInfoBean;
import com.example.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
public class UserController {
    // 使用ioc、di进行依赖注入
    @Autowired
    private IUserService userService;

    @RequestMapping("/login")
    public String doLogin(UserInfoBean userInfoBean) {
        // 调用service层进行登录业务逻辑处理
        List<UserInfoBean> userInfoBeanList =  userService.queryForLogin(userInfoBean);
        // 判断是否登录成功
        if(userInfoBeanList != null && userInfoBeanList.size() > 0) {
            // 登录成功
            // 返回登录成功的视图名
            return "login/main";
        } else {
            // 登录失败，返回登录页面
            return "index";
        }
    }
}
